<!DOCTYPE html>
{extend name="common/application" /}
{block name="title"}<title id="title">个人中心-店铺收藏</title>{/block}
{block name="css"}
<link rel="stylesheet" type="text/css" href="_CSS_/help.css"/>
<link rel="stylesheet" href="_CSS_/collect.css"/>
<style>
    .sp1 {
        width: 34px;
        height: 16px;
        background-color: #17c6ac;
        color: #ffffff;
        font-size: 12px;
        line-height: 16px;
        text-align: center;
        margin-right: 10px;
    }
	.ml110{margin-left:110px !important;}
</style>
{/block}


<!-- 主体内容 -->
{block name="content"}


<div class="main">
    <div class="mainBody normalBox clearfix">
        <!--左菜单-->
        <ul class="menuList fl">
            <li>
                <a class="menuItem dropBg" href="personal.html"><span class="icons icon-account"></span>账户管理</a>
                <div class="childMenu">
                    <a class="menuchildItem" href="personal.html">个人资料</a>
                    <a class="menuchildItem" href="certification.html">实名认证</a>
                    <a class="menuchildItem" href="account.html">账户安全</a>
                </div>
            </li>
            <li>
                <a class="menuItem dropBg" href="order.html"><span class="icons icon-order"></span>我的订单</a>
                <div class="childMenu">
                    <a class="menuchildItem" href="order.html">我的订单</a>
                </div>
            </li>
            <li class="showChild">
                <a class="menuItem dropBg" href="collect_news.html"><span class="icons icon-collection"></span>我的收藏</a>
                <div class="childMenu">
                    <a class="menuchildItem" href="collect_news.html">资讯收藏</a>
                    <a class="menuchildItem" href="collect_course.html">课程收藏</a>
                    <a class="menuchildItem" href="collect_products.html">商品收藏</a>
                    <a class="menuchildItem activeMenu" href="collect_stores.html">店铺收藏</a>
                </div>
            </li>
            <li>
                <a class="menuItem dropBg" href="address.html"><span class="icons icon-address"></span>地址管理</a>
                <div class="childMenu">
                    <a class="menuchildItem" href="address.html">地址管理</a>
                </div>
            </li>
            <li>
                <a class="menuItem dropBg" href="judge.html"><span class="icons icon-evaluate"></span>评价管理</a>
                <div class="childMenu">
                    <a class="menuchildItem" href="judge.html">评价管理</a>
                </div>
            </li>
            <li>
                <a class="menuItem dropBg" href="complain.html"><span class="icons icon-price"></span>申述退款</a>
                <div class="childMenu">
                    <a class="menuchildItem" href="complain.html">申述</a>
                    <a class="menuchildItem" href="refund_money.html">退款</a>
                </div>
            </li>
            <li class="bb0">
                <a class="menuItem dropBg" href="message.html"><span class="icons icon-news"></span>消息中心</a>
                <div class="childMenu">
                    <a class="menuchildItem" href="message.html">消息中心</a>
                </div>
            </li>
        </ul>
        <!--右内容-->
        <div class="menuContent fr">
            <div class="menuConHeader">
                <!--面包屑导航-->
                <div class="breadcrumb">
                    <p>当前位置：
                        <a href="collect_news.html">我的收藏</a> &gt;
                        <a class="curPage" href="javascript:;">店铺收藏</a>
                    </p>
                </div>
            </div>
            <div class="menuConBody">
                <div class="hasData">
                    <!--筛选-->
                    <div class="one_tab">
                        <a class="oneType active_on" href="javascript:;" value="5">个人店铺</a>
                        <a class="oneType" href="javascript:;" value="6">企业店铺</a>
                    </div>
                    <!--无数据-->
                    <div class="noData hide">
                        <img src="_IMG_/Nocollection.png"/>
                        <p>您还没有相关收藏的店铺信息！</p>
                    </div>
                    <div class="tableHeader">
                        <input class="mainCheck" type="checkbox"/>全选
                        <span class="ml120">商品信息</span>
                        <span class="ml370">收藏时间</span>
                        <span class="ml93">操作</span>
                    </div>
                    <div class="tableBody">

                    </div>
                    <div class="tableFoot">
                        <input class="mainCheck" type="checkbox"/>全选
                        <a class="cancelAll" href="javascript:;">取消收藏</a>
                    </div>
                    <!--分页-->
                    <div id="page"></div>
                    <input type="hidden" id="uid">
                    <input type="hidden" id="all">
                </div>
            </div>
        </div>
    </div>
</div>


{/block}


{block name="js"}
<script src="_P_/laydate/laydate.js"></script>
<script src="_P_/layer/layer.js"></script>
<script src="_JS_/time.js"></script>
<script type="text/javascript">


    $(document).ready(function () {
        /*分类切换*/
        $('.oneType').on('click', function () {
            var userinfo = $.cookie('userinfo');
            var user_login = $.base64.decode(userinfo).split(",");
            var uid = user_login[0];
            $('.oneType').removeClass('active_on');
            $(this).addClass('active_on');
            var all = $(this).attr('value');
            $("#all").val(all);
            get_trade(uid, 1, all);
        });
        /*全选*/
        $(".mainCheck").change(function () {
            if ($(this).prop('checked')) {
                $(".mainCheck").prop('checked', true);
                $('.childCheck').prop('checked', true);
            } else {
                $(".mainCheck").prop('checked', false);
                $('.childCheck').prop('checked', false);
            }
        });
        /*勾选*/
        $('.childCheck').change(function () {
            var len = $('.items').length;
            var lens = $(this).parents('.tableBody').find('input[type="checkbox"]:checked').length;
            if ($(this).prop('checked')) {
                if (len == lens) {
                    $('.mainCheck').attr('checked', true);
                } else {
                    $('.mainCheck').attr('checked', false);
                }
            } else {
                $('.mainCheck').attr('checked', false);
            }
        });
    });

    $(function () {
        var userinfo = $.cookie('userinfo');
        if (userinfo) {
            var user_login = $.base64.decode(userinfo).split(",");
            var uid = user_login[0];
            get_trade(uid, 1, 5);
            //$('.title').html('个人中心');
        } else {
            $('.hasData').html('');
            layer.msg('还未登录！', {icon: 5});
        }

        //取消收藏
        $('.cancelAll').on('click', function () {
            var index = $('.one_tab a[class="oneType active_on"]').attr('value');
            var arrs = [];
            $('.tableBody input:checked').parents('.products').each(function () {
                arrs.push($(this).attr('num'));
            });
            if (arrs.length == 0) {
                layer.msg('请选择需要取消的!', {icon: 1, time: 1000});
                return false;
            }
            var ids = arrs.join(",");
            cancle_collect(ids, index);
        });

    })

    function cancle_collect(id, type) {
        var userinfo = $.cookie('userinfo');
        var user_login = $.base64.decode(userinfo).split(",");
        var uid = user_login[0];
        var page = $('.tableBody').attr('num');
        $.ajax({
            type: "get",
            url: "/index.php/api/shop/info_del",
            data: {
                'id': id,
                'uid': uid,
                'type': type
            },
            dataType: 'jsonp',
			beforeSend: function () {
                var index = layer.load(1, {
                    shade: [0.1, '#333333'] //0.1透明度的白色背景
                });
			},
            success: function (msg) {
                layer.closeAll();
                if (msg.code == 200) {
                    layer.msg('取消收藏成功!', {icon: 1});
                    get_trade(uid, page, type);

                }
            }
        })
    }

    function get_trade(uid, page, all) {
        $.ajax({
            type: "get",
            url: "/index.php/api/shop/info_list",
            data: {
                'uid': uid,
                'page': page,
                'all': all
            },
            dataType: 'jsonp',
            success: function (msg) {
                if (msg.code == 200) {
                    var html = '';
                    if (msg.data.data.length > 0) {
                        for (var i = 0; i < msg.data.data.length; i++) {
                            html += '<div class="items courses products" num="' + msg.data.data[i].id + '"><input class="fl childCheck" type="checkbox"/>' +
                                '<div class="basicInfo"><a class="storeLogo" href="/index.php' +
                                '/index/trade/center.html?' + msg.data.data[i].id + '">' +
                                '<img width="100px" height="100px" src="/Images/information/' + msg.data.data[i].image + '" class="icon-wapper hide">' +
                                '<img width="100px" height="100px" src="/Images/information/' + msg.data.data[i].image + '" class="icon">' +
                                '</a><h4 class="storeNames">' + msg.data.data[i].name + '</h4><p>卖家：' +
                                '<span class="sellerman">' + msg.data.data[i].username + '</span></p><br>';
                            if (msg.data.data[i].shop_id == 1) {
                                html += '<span class="icons sp1">个人</span><span class="icons icon-ensure"></span><p class="ml110">';
                            } else {
                                html += '<span class="icons sp1">企业</span><span class="icons icon-ensure"></span><p class="ml110">';
                            }

                            if (msg.data.label.length > 0) {
                                for (var j = 0; j < msg.data.label.length; j++) {
                                    if ($.inArray(msg.data.label[j].id + '', msg.data.data[i].label) != -1) {
                                        html += '<span class="labels">' + msg.data.label[j].name + '</span>';
                                    }
                                }
                            }
                            html += '</p></div><span class="times">' + getMyDate(msg.data.data[i].time * 1000) + '</span>' +
                                '<a class="cancelCollect" onclick="cancle_collect(' + msg.data.data[i].id + ',' + all + ')" href="javascript:;">取消收藏</a></div>';
                        }
                        $('.noData').addClass('hide');
                        $('.tableHeader').removeClass('hide');
                        $('.tableBody').removeClass('hide');
                        $('.tableFoot').removeClass('hide');
                        $('.tableBody').html(html);
                        if (msg.data.count > 0) {
                            $('.tableBody').attr('num', page);
                            $('#page').html(msg.data.render);
                            $("#pagination").delegate("a", "click", function () {
                                if (all == '') {
                                    all = 5;
                                }
                                var num = $(this).attr("num");
								
                                if (num) {
                                    get_trade(uid, num, all);
                                }
                            });
							var pages = Math.ceil(msg.data.count / 3);
							$("#GO").on('click',function(){
								var king = $("#go").val();
								if(king > pages){
										layer.alert("最多输入"+pages+"页");
										return;
								}
								postfile(uid ,king, all);
							});
                        }
                    } else {
                        $('#page').html("");
                        $('.noData').removeClass('hide');
                        $('.tableHeader').addClass('hide');
                        $('.tableBody').addClass('hide');
                        $('.tableFoot').addClass('hide');
                    }

                }
            }

        });
    }
</script>
{/block}

			